home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / MetalThemeMenu.java < prev    next >
Text File  |  1998-06-30  |  2KB  |  67 lines

  1. /* 
  2.  * @(#)MetalThemeMenu.java    1.2 98/02/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21.  
  22. import com.sun.java.swing.plaf.metal.*;
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.border.*;
  25. import java.awt.*;
  26. import java.awt.event.*;
  27.  
  28. /**
  29.  * This class describes a theme using "green" colors.
  30.  *
  31.  * @version 1.2 02/05/98
  32.  * @author Steve Wilson
  33.  */
  34. public class MetalThemeMenu extends JMenu implements ActionListener{
  35.  
  36.   MetalTheme[] themes;
  37.   public MetalThemeMenu(String name, MetalTheme[] themeArray) {
  38.     super(name);
  39.     themes = themeArray;
  40.     ButtonGroup group = new ButtonGroup();
  41.     for (int i = 0; i < themes.length; i++) {
  42.         JRadioButtonMenuItem item = new JRadioButtonMenuItem( themes[i].getName() );
  43.     group.add(item);
  44.         add( item );
  45.     item.setActionCommand(i+"");
  46.     item.addActionListener(this);
  47.     if ( i == 0)
  48.         item.setSelected(true);
  49.     }
  50.  
  51.   }
  52.  
  53.   public void actionPerformed(ActionEvent e) {
  54.     String numStr = e.getActionCommand();
  55.     MetalTheme selectedTheme = themes[ Integer.parseInt(numStr) ];
  56.     MetalLookAndFeel.setCurrentTheme(selectedTheme);
  57.     try {
  58.     UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  59.     } catch (Exception ex) {
  60.         System.out.println("Failed loading Metal");
  61.     System.out.println(ex);
  62.     }
  63.  
  64.   }
  65.  
  66. }
  67.